home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 15 code / Floating Windows / Floating Windows Code / Shell Code / appleEventHandlers.c next >
Encoding:
Text File  |  1995-04-06  |  5.4 KB  |  188 lines  |  [TEXT/MMCC]

  1. // If the interfaces aren't included yet, do the standard includes. Otherwise, precompiled headers
  2. // have been loaded already, thank you very much
  3. #ifndef __TYPES__
  4.     #include <Types.h>
  5.     #include <AppleEvents.h>
  6.     #include <Desk.h>
  7.     #include <Dialogs.h>
  8.     #include <Editions.h>
  9.     #include <Events.h>
  10.     #include <Menus.h>
  11.     #include <SegLoad.h>
  12.     #include <TextUtils.h>
  13.     #include <ToolUtils.h>
  14.     #include <Windows.h>
  15. #endif
  16.  
  17. #include "FloaterSample.h"
  18. #include "appleEventHandlers.h"
  19. #include "eventHandler.h"
  20. #include "fileMenuRoutines.h"
  21. #include "menuDispatch.h"
  22.  
  23. /*    Private routines */
  24.     
  25. pascal    Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn);
  26.     
  27. /* Globals */
  28.     
  29. extern Boolean    gDone;                            /* Set to true if user selects Quit */
  30. extern Boolean    gInBackground;                    /* Set to true if app is switched into background */
  31.  
  32. /*    Handle the ‘oapp’ AppleEvent.    */
  33.  
  34. pascal OSErr    OAPPHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  35. {
  36. #pragma unused (reply, handlerRefCon)
  37.  
  38.     OSErr        oappErr;
  39.     AEKeyword    missedKeyWord;
  40.     DescType    actualType;
  41.     Size        actualSize;
  42.     
  43.     //DebugStr("\pOAPP");
  44.     oappErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  45.  
  46.     if (!oappErr)                    /* If no error, then a missing parameter was found */
  47.         return errAEParamMissed;
  48.     
  49.     /*    Do whatever needs to be done when starting up and return noErr */
  50.     if(FrontNonFloatingWindow() == nil)
  51.         CreateNewDocumentWindow();
  52.  
  53.     return    noErr;
  54. }
  55.  
  56. /*    Handle the ‘odoc’ AppleEvent.    */
  57.  
  58. pascal OSErr    ODOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  59. {
  60. #pragma unused (reply, handlerRefCon)
  61.  
  62.     OSErr            odocErr;
  63.     AEKeyword        missedKeyWord;
  64.     DescType        actualType;
  65.     Size            actualSize;
  66.     AEDescList        documentList;
  67.     long            itemsInList;
  68.     long            i;
  69.     AEKeyword        keyWord;
  70.     DescType        typeCode;
  71.     FSSpec            documentFileSpec;
  72.     TargetID        senderType;
  73.     OSType            senderCreator;
  74.     ProcessSerialNumber    thePSN;
  75.     
  76.     //DebugStr("\pODOC");
  77.     odocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList);    /* Get list of documents to open */
  78.     if (odocErr)
  79.         return odocErr;
  80.         
  81.     odocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  82.  
  83.     if (!odocErr)                    /* If no error, then a missing parameter was found */
  84.         return errAEParamMissed;
  85.     
  86.     /* 
  87.         If we’re in the background, see if the event was sent from the Finder.  If so,
  88.         switch to the front.
  89.     */
  90.     
  91.     if (gInBackground) {
  92.         odocErr = AEGetAttributePtr(&theAppleEvent, keyAddressAttr, typeTargetID, &actualType, (Ptr) &senderType, sizeof(senderType), &actualSize);
  93.         BlockMove((Ptr) (&(senderType.name.u.portTypeStr)+1), (Ptr) &(senderCreator), 4);
  94.         if (senderCreator == 'MACS') {
  95.             thePSN.highLongOfPSN = 0;
  96.             thePSN.lowLongOfPSN = kCurrentProcess;
  97.             SetFrontProcess(&thePSN);
  98.         }
  99.     }
  100.  
  101.     /* Open all the documents in documentList */
  102.     
  103.     odocErr = AECountItems(&documentList, &itemsInList);        /* Get number of documents */
  104.     
  105.     for (i = 1; i <= itemsInList; i++) {
  106.         odocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
  107.         DoOpenFile(&documentFileSpec);
  108.     }
  109.         
  110.     odocErr = AEDisposeDesc(&documentList);            /* Dispose of AE structure created by AEGetParamDesc */
  111.     return    noErr;
  112. }
  113.  
  114. /*    Handle the ‘pdoc’ AppleEvent.    */
  115.  
  116. pascal OSErr    PDOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  117. {
  118. #pragma unused (reply, handlerRefCon)
  119.  
  120.     OSErr        pdocErr;
  121.     AEKeyword    missedKeyWord;
  122.     DescType    actualType;
  123.     Size        actualSize;
  124.     AEDescList    documentList;
  125.     long        itemsInList;
  126.     long        i;
  127.     AEKeyword    keyWord;
  128.     DescType    typeCode;
  129.     FSSpec        documentFileSpec;
  130.     
  131.     pdocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList);    /* Get list of documents to open */
  132.     
  133.     pdocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  134.  
  135.     if (!pdocErr)                    /* If no error, then a missing parameter was found */
  136.         return errAEParamMissed;
  137.     
  138.     /* Print all the documents in documentList */
  139.     
  140.     pdocErr = AECountItems(&documentList, &itemsInList);        /* Get number of documents */
  141.     
  142.     for (i = 1; i <= itemsInList; i++) {
  143.         pdocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
  144.         DoPrintFile(&documentFileSpec);
  145.     }
  146.         
  147.     pdocErr = AEDisposeDesc(&documentList);                    /* Dispose of AE structure created by AEGetParamDesc */
  148.     return    noErr;
  149. }
  150.  
  151. /*    Handle the ‘quit’ AppleEvent.    */
  152.  
  153. pascal OSErr    QUITHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  154. {
  155. #pragma unused (reply, handlerRefCon)
  156.  
  157.     OSErr        quitErr;
  158.     AEKeyword    missedKeyWord;
  159.     DescType    actualType;
  160.     Size        actualSize;
  161.     
  162.     quitErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  163.  
  164.     if (!quitErr)                    /* If no error, then a missing parameter was found */
  165.         return errAEParamMissed;
  166.     
  167.     /*    Do whatever needs to be done when quitting and return noErr */
  168.     
  169.     gDone = true;    
  170.     return    noErr;
  171. }
  172.  
  173. pascal    Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn)
  174. {    
  175.     switch (theEventRecord->what) {
  176.         case updateEvt:
  177.         case activateEvt:
  178.         case osEvt:            HandleEvent(theEventRecord);
  179.                             break;
  180.         case nullEvent:        *mouseRgn = nil;
  181.                             *sleepTime = 15;
  182.                             break;
  183.     }
  184.     return false;
  185. }
  186.  
  187.  
  188.